{extend name="platform/base" /}
{block name="resources"/}
<script src="ADMIN_JS/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<style  type="text/css">
.set-style{
	width:100%;
}
.set-style dl{
	width:100%;
	font-size: 0;
	/* line-height: 20px; */
	clear: both;
	padding: 0;
	margin: 0;
	border-bottom: dotted 1px #E6E6E6;
	overflow: hidden;
}
.set-style dl dt{
	font-size: 12px;
	line-height: 32px;
	vertical-align: top;
	letter-spacing: normal;
	word-spacing: normal;
	text-align: right;
	display: inline-block;
	width: 19%;
	padding: 10px 1% 10px 0;
	margin: 0;
	font-weight:normal;
}
.set-style dl dd{
	font-size: 12px;
	line-height: 32px;
	vertical-align: top;
	letter-spacing: normal;
	word-spacing: normal;
	display: inline-block;
	width: 78%;
	padding: 10px 0 10px 0;
}
.set-style dl dd input[type="text"]{
	font: 12px/20px Arial;
	color: #777;
	background-color: #FFF;
	vertical-align: top;
	display: inline-block;
	height:24px;
	line-height:24px;
	padding: 4px;
	border: 1px solid #CCC;
	outline: 0 none;
	width: 400px;
	margin:0;
}
.set-style dl dd textarea{
    font: 12px/20px Arial;
    color: #777;
    background-color: #FFF;
    vertical-align: top;
    display: inline-block;
    height: 60px;
    padding: 4px;
    border: solid 1px #CCC;
    outline: 0 none;
	width: 400px;
	margin:0;
}
.hint{
    font-size: 12px;
    line-height: 16px;
    color: #BBB;
    margin-top: 10px;
}
.set-style dl dd p img{
	border: medium none;
	vertical-align: middle;
}
.class-Logo{
	background-color: #FFF;
	position: relative;
	z-index: 1;
}
.class-Logo p{
	width: 120px;
	height: 100px;
	line-height: 0;
	background-color: #FFF;
	text-align: center;
	vertical-align: middle;
	display: table-cell;
	*display: block;
	overflow: hidden;
	    margin: 0 0 10px;
		border: dashed 1px #E6E6E6;
}
.class-Logo p img{
	max-width: 120px;
	max-height: 100px;
	border: medium none;
	vertical-align: middle;
	margin-top: expression(60-this.height/2);
	*margin-top: expression(30-this.height/2);
}

.set-style dl dd p{
	margin-bottom:0;
}

.table-div  table tr td{
	    border: 1px solid #e6e6e6;
    padding: 10px;
}
.goodlist-table tr td{
	    border: 1px solid #e6e6e6;
    padding: 10px;
}
.form-horizontal .control-group {
    margin-bottom: 0px;
}
.form-horizontal .controls {
    margin-left: 20px; 
}
.help-inline{
	    height: 30px;
    	line-height: 30px;
}
input[type="radio"]{
	margin-top:6px;
}
.controls table tr td input[type="radio"]{
	margin:0px;
}
</style>
 {/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt>活动名称:</dt>
		<dd><input type="text" id="discount_name" maxlength="10" value="{$info['discount_name']}"></dd>
	</dl>
	<dl>
		<dt>活动有效期:</dt>
		<dd>
			<input class="input-medium" type="text" id="start_time" value="{$info['start_time']}" style="width:250px;"onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss'})">
			<span class="mlr5">-</span> 
			<input class="input-medium" size="15"type="text" id="end_time" value="{$info['end_time']}" style="width:250px;"onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss'})">
		</dd>
	</dl>
	{include file="platform/Promotion/selectGoods" /}
	<input type="hidden" id="discount_id" value="{$info['discount_id']}">
	<button class="edit_button" onclick="updateDiscount();">提交</button>
</div>
{include file="platform/openDialog" /}
<script>
function join(goods_id,e){
	if($("#selected_"+goods_id).length > 0){
		return false;
	}else{
		var html = '<tr id="selected_'+goods_id+'">'+$(e).parents("tr").html()+'</tr>';
		$(".select-two tbody").append(html);
		var a = '<a href="javascript:;" class="btn btn-dange js-remove-reward" onclick="cancel_join('+goods_id+',this)">取消参加</a>';
		$(e).parent("td").html(a);
		$("#selected_"+goods_id+" .goods-opt").html(a);
		var html_td = '<td><div class="input-group" style="line-height:32px;"><span class="input-group-addon">打折</span><input type="text" name="discount" style="width:100px;"  id="discount_'+goods_id+'" class="form-control" value="10.0"><span class="input-group-addon">折</span></div></td>';
		$("#selected_"+goods_id+" .goods-meta").after(html_td);
		
	}
	
}
function addselected(goods_list){
	var html = '';
	for(var i=0;i<goods_list.length;i++){
		 html += '<tr id="selected_'+goods_list[i]+'">'+$("#select_"+goods_list[i]).html()+'</tr>';
	}
	$(".select-two tbody").append(html);
	show_discount();
}
$(function(){
	$('.type_dl dd').hide();
	$("#some_pro").show();
	$(".select-two thead th").eq(1).after("<th></th>");
	var goods_id_array = {$info}.goods_id_array;
	LoadingInfo(goods_id_array);
	
});
function show_discount(){
	var goods_list = {$info}.goods_list;
	for(var j=0; j < goods_list.length;j++){
		var html_td = '<td><div class="input-group" style="line-height:32px;"><span class="input-group-addon">打折</span><input type="text" name="discount" style="width:100px;"  id="discount_'+goods_list[j]['goods_id']+'" class="form-control" value="'+goods_list[j]['discount']+'"><span class="input-group-addon">折</span></div></td>';
		$("#selected_"+goods_list[j]['goods_id']+" .goods-meta").after(html_td);
	}
}
	//保存
	function updateDiscount(){   
		var discount_id = $("#discount_id").val();
		var discount_name = $("#discount_name").val();
		var start_time = $("#start_time").val();
		var end_time = $("#end_time").val();
		var obj = $(".select-two table input[type=checkbox][name='sub']");
		var goods_id_array = '';
		obj.each(function(i){
			var dis = $("#discount_"+obj.eq(i).val()).val() ? $("#discount_"+obj.eq(i).val()).val() : 10;
			goods_id_array += ','+obj.eq(i).val()+':'+ dis;
		});
		goods_id_array = goods_id_array.substring(1);
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/Promotion/updateDiscount')}",
			data : {
				'discount_id' : discount_id,
				'discount_name' : discount_name,
				'start_time' : start_time,
				'end_time' : end_time,
				'goods_id_array' : goods_id_array,
			},
			async : true,
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', data["message"], "{:__URL('PLATFORM_MAIN/Promotion/getDiscountList')}");
				}else{
					showMessage('error', data["message"]);
				}	
			}
		});
	}
</script>
{/block}